package blackhouse.advanced.serialization;
import java.io.*;
public class Serialization
{
	public static void main(String[] args) throws Exception
	{
            Student stu1 = new Student(19, "zhangsan", 25, "huaxue");
            Student stu2 = new Student(20, "lisi", 23, "wuli");
             FileOutputStream fos = new FileOutputStream("student.txt");
            ObjectOutputStream os = new ObjectOutputStream(fos);
            os.writeObject(stu1);
            os.writeObject(stu2);
            os.close();
             FileInputStream fis= new FileInputStream("student.txt");
             ObjectInputStream ois= new ObjectInputStream(fis);
              stu1  = (Student) ois.readObject();    
              stu2  =  (Student)ois.readObject();
              ois.close();
              
              System.out.println("id: "+stu1.id);
              System.out.println("name: "+stu1.name);
              System.out.println("age: "+stu1.age);
              System.out.println("department: "+stu1.department);
              
              System.out.println("id: "+stu2.id);
              System.out.println("name: "+stu2.name);
              System.out.println("age: "+stu2.age);
              System.out.println("department: "+stu2.department);
	}

}
